package com.booksystem.campuslibrarymanagementsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.booksystem.campuslibrarymanagementsystem.commen.result.adminresult.SendEmailManagementR.GetEmailR;
import com.booksystem.campuslibrarymanagementsystem.entity.AccountTable;
import com.booksystem.campuslibrarymanagementsystem.entity.UserTable;
import com.booksystem.campuslibrarymanagementsystem.mapper.AccountTableMapper;
import com.booksystem.campuslibrarymanagementsystem.service.AccountTableService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class  AccountTableServiceImpl extends ServiceImpl<AccountTableMapper, AccountTable> implements AccountTableService {
    @Autowired
    AccountTableMapper accountTableMapper;

    @Override
    public AccountTable queryByAccount(String account) {
        return accountTableMapper.queryByAccount(account);
    }

    @Override
    public List<AccountTable> queryByState(String state) {
        return accountTableMapper.queryByState(state);
    }

    @Override
    public boolean upDataPswAndSalt(String account, String password, String salt) {
        return accountTableMapper.upDataPswAndSalt(account,password,salt);
    }

    @Override
    public boolean upDataPswAndSaltAndState(String account, String password, String salt, String state) {
        return accountTableMapper.upDataPswAndSaltAndState(account,password,salt,state);
    }

    @Override
    public boolean upDataState(String account, String state) {
        return accountTableMapper.upDataState(account,state);
    }

    @Override
    public boolean upDataIdentity(String account, String identity) {
        return accountTableMapper.upDataIdentity(account,identity);
    }

    @Override
    public List<AccountTable> selectListAccount(String account, String name, String identity, String state) {
        QueryWrapper<AccountTable> queryWrapper = new QueryWrapper<>();
        // 构建查询条件
        if (account != null && !account.isEmpty()) {
            queryWrapper.like("account", account);
        }
        if (name != null && !name.isEmpty()) {
            queryWrapper.like("name", name);
        }
        if (identity != null && !identity.isEmpty()) {
            queryWrapper.like("identity", identity);
        }
        if (state != null && !state.isEmpty()) {
            queryWrapper.like("state", state);
        }
        // 执行查询
        return accountTableMapper.selectList(queryWrapper);
    }

    @Override
    public boolean upDataName(String account, String name) {
        return accountTableMapper.upDataName(account,name);
    }

    @Override
    public List<AccountTable> queryByEmail(String email) {
        return accountTableMapper.queryByEmail(email);
    }

    @Override
    public boolean upDataEmailAndName(String account, String email, String name) {
        return accountTableMapper.upDataEmailAndName(account,email,name);
    }

    @Override
    public List<GetEmailR> GetEmails() {
        return accountTableMapper.GetEmails();
    }


    @Override
    public String getAccountId(@Param("name") String name){
        return accountTableMapper.getAccountId(name);
    }

    @Override
    public boolean updateAccount(AccountTable account){
        return accountTableMapper.updateAccount(account);
    }

    @Override
    public boolean updateAccountemail(AccountTable account){
        return accountTableMapper.updateAccountemail(account);
    }

}
